var api = require('../../../config/api.js');
var wxcache = require('../../../utils/wxcache.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    dataList: [
      // {
      //   goods_id: 1,
      //   goods_title: '商品标题1',
      //   goods_img: 'http://img.51miz.com/Element/00/83/77/33/843a123e_E837733_e92b9cac.png!/quality/90/unsharp/true/compress/true/format/png/fh/630',
      //   goods_xiaoliang: '0',
      //   goods_price: '60'
      // }, {
      //   goods_id: 1,
      //   goods_title: '商品标题2',
      //   goods_img: 'http://img.51miz.com/Element/00/83/77/33/843a123e_E837733_e92b9cac.png!/quality/90/unsharp/true/compress/true/format/png/fh/630',
      //   goods_xiaoliang: '0',
      //   goods_price: '70'
      // }, {
      //   goods_id: 1,
      //   goods_title: '商品标题3',
      //   goods_img: 'http://img.51miz.com/Element/00/83/77/33/843a123e_E837733_e92b9cac.png!/quality/90/unsharp/true/compress/true/format/png/fh/630',
      //   goods_xiaoliang: '0',
      //   goods_price: '80'
      // }, {
      //   goods_id: 1,
      //   goods_title: '商品标题4',
      //   goods_img: 'http://img.51miz.com/Element/00/83/77/33/843a123e_E837733_e92b9cac.png!/quality/90/unsharp/true/compress/true/format/png/fh/630',
      //   goods_xiaoliang: '0',
      //   goods_price: '90'
      // }, {
      //   goods_id: 1,
      //   goods_title: '商品标题5',
      //   goods_img: 'http://img.51miz.com/Element/00/83/77/33/843a123e_E837733_e92b9cac.png!/quality/90/unsharp/true/compress/true/format/png/fh/630',
      //   goods_xiaoliang: '0',
      //   goods_price: '110'
      // }
    ]
  },
  /**
     * 生命周期函数--监听页面加载
     */
  onLoad: function (options) {
    const that = this;
    var uid = wxcache.get("userInfo").id;
    var url = api.goodOrderList;
    var data = {
      startIndex: 1,
      pageSize: 500,
      userId: uid,
      bizType:2
    };
    wx.request({
      url: url,
      method: "GET",
      data: data,
      success: function (res) {
        if (res.data.message == "ok") {
          var orderDetailList = res.data.responseBody.orderDetailList;
          var goods_list = [];
          for (var i = 0; i < orderDetailList.length; i++){
            if (orderDetailList[i].status == "PAY_SUCCESS"){
              goods_list.push({
                goods_id: orderDetailList[i].orderId,
                goods_title: orderDetailList[i].campaignName,
                goods_img: orderDetailList[i].primaryImageUrl[0],
                goods_price: orderDetailList[i].campaignPrice
              })
            }
          }
          that.setData({
            dataList: goods_list
          })
        }
      }
    });
    that.setData({
      activeIndex: options.activeIndex
    });
  }

})